﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caliburn.Micro;

namespace Zcu.PanelComposer.Views.Logging
{
    /// <summary>
    /// Implementace Log3net loggeru pro potreby Caliburn.Micro.
    /// http://buksbaum.us/2010/08/08/how-to-do-logging-with-caliburn-micro/
    /// </summary>
    public class Log4netLogger : ILog
    {
        #region Fields

        /// <summary>
        /// Reference na logger.
        /// </summary>
        private readonly log4net.ILog _innerLogger;

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Log4netLogger"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        public Log4netLogger(Type type)
        {
            _innerLogger = log4net.LogManager.GetLogger(type);
        }

        #endregion

        #region ILog Members

        /// <summary>
        /// Logs the exception.
        /// </summary>
        /// <param name="exception">The exception.</param>
        public void Error(Exception exception)
        {
            _innerLogger.Error(exception.Message, exception);
        }

        /// <summary>
        /// Logs the message as info.
        /// </summary>
        /// <param name="format">A formatted message.</param>
        /// <param name="args">Parameters to be injected into the formatted message.</param>
        public void Info(string format, params object[] args)
        {
            _innerLogger.InfoFormat(format, args);
        }
        /// <summary>
        /// Logs the message as a warning.
        /// </summary>
        /// <param name="format">A formatted message.</param>
        /// <param name="args">Parameters to be injected into the formatted message.</param>
        public void Warn(string format, params object[] args)
        {
            _innerLogger.WarnFormat(format, args);
        }

        #endregion
    }
}
